package com.itheima.activiti01.test;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

/**
 * @program: Activiti01
 * @description: 使用监听设置处理人Demo
 * @author: ZhuYingjie
 * @create: 2025-02-18 08:37
 **/
public class ActivitiListenerAssigneeDemo {

    /**
     * 部署流程定义
     */
    @Test
    public void testDeployment(){
//        1、创建ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        2、得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();
//        3、使用RepositoryService进行部署
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("bpmn/demo-listen.bpmn") // 添加bpmn资源
                .name("测试监听器")
                .deploy();
//        4、输出部署信息
        System.out.println("流程部署id：" + deployment.getId());
        System.out.println("流程部署名称：" + deployment.getName());
    }

    @Test
    public void testStartProcess(){
//        1. 获得ProcessEngine
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        2. 获取RunTimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
//        3. 通过流程key启动流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testListener");
        System.out.println("流程实例ID:"+processInstance.getProcessInstanceId());
    }

}
